// 167. 两数之和 II - 输入有序数组

/**
 * @param {number[]} numbers
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function (numbers, target) {
    for (let i = 0; i < numbers.length; i++) {
        // 两个数的位置不一样，如果当前的为一个答案，另外一个答案一定在右侧
        let left = i + 1,
            right = numbers.length - 1,
            mid;
        while (left <= right) {
            mid = ((right - left) >> 1) + left;
            if (numbers[mid] < target - numbers[i]) {
                left = mid + 1;
            } else if (target - numbers[i] == numbers[mid]) {
                return [i + 1, mid + 1];
            } else {
                right = mid - 1;
            }
        }
    }
    // 没有找到，返回[-1,-1]
    return [-1, -1];
};
